package cn.hp.service.impl;

import cn.hp.bean.Customer;
import cn.hp.bean.CustomerExample;
import cn.hp.mapper.CustomerMapper;
import cn.hp.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public Customer findCuPhone(String phone) {
        CustomerExample example=new CustomerExample();
        CustomerExample.Criteria criteria = example.createCriteria();
        criteria.andPhoneEqualTo(phone);
        List<Customer> list = customerMapper.selectByExample(example);
        Customer customer=null;
        if(list.size()>0){
            return customer=list.get(0);
        }else {
            return customer;
        }
    }

    @Override
    public int addCusromer(String phone, String name, String car) {
        Customer customer=new Customer();
        customer.setName(name);
        customer.setPhone(phone);
        customer.setCreatetime(new Date());
        customer.setCar(car);
        int i = customerMapper.insertSelective(customer);
        return i;
    }
}
